
#import "InfomationViewController.h"
#import "TabbarViewController.h"
#import "ICSDrawerController.h"
#import "AddressBookLeftViewController.h"
#import "TouristViewController.h"

@interface InfomationViewController()<UIScrollViewDelegate>
{
    UIScrollView *_scrollView;
    UIPageControl *_pageControl;
    int _lastPage;
}
@end

@implementation InfomationViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    CGFloat w = self.view.frame.size.width;
    CGFloat h = self.view.frame.size.height;
    int kCount = 3;
    
    _scrollView = [[UIScrollView alloc] init];
    _scrollView.frame = CGRectMake(0, -20, w, h+20);
    _scrollView.contentSize = CGSizeMake(kCount * w, 0);
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.pagingEnabled = YES;
    _scrollView.bounces=NO;
    _scrollView.delegate = self;
    [self.view addSubview:_scrollView];
    
    for (int i = 0; i < kCount; i++) {
        UIImageView *imageView = [[UIImageView alloc]  init];
        imageView.frame = CGRectMake(i * w, 20-(YNEW), w, h);
        //        UIDevice *dev = [UIDevice currentDevice];
        
        NSString *imgName = [NSString stringWithFormat:@"pic%d.png", i + 1];
        if (SCREEN_HEIGHT>480) {
            imgName = [NSString stringWithFormat:@"pic%d-568h.png", i + 1];
            
        }
        imageView.image = [UIImage imageNamed:imgName];
        
        [_scrollView addSubview:imageView];
    }
    
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lastonClick)];
    [_scrollView addGestureRecognizer:singleTap];
    
    _pageControl = [[UIPageControl alloc] init];
    _pageControl.center = CGPointMake(w * 0.5, h - 20);
    _pageControl.bounds = CGRectMake(0, 0, 150, 50);
    _pageControl.numberOfPages = kCount;
    _pageControl.enabled = NO;
    
    [self.view addSubview:_pageControl];
}

-(void)lastonClick
{
    if(_pageControl.currentPage==2)
    {
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setBool:YES forKey:@"isNoNeedInfo"];
        [defaults synchronize];
        
        
        TouristViewController *info = [[TouristViewController alloc] init];
        [self.navigationController pushViewController:info animated:YES];
    }
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    int page = scrollView.contentOffset.x / scrollView.frame.size.width;
    _pageControl.currentPage = page;
    if (2 == page && _lastPage == page && page >= _lastPage) {
        return;
    }
    _lastPage = page;
}

@end
